﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace iContactCfg
{
  public partial class MainForm : Form
  {
    private FieldsFactory fieldsFactory = null;

    public MainForm()
    {
      InitializeComponent();

      try
      {
        this.fieldsFactory = new FieldsFactory(this);
      }
      catch (Exception exception)
      {
        MessageBox.Show(exception.Message + "\r\n" + exception.StackTrace, "Fatal Error");
        this.Close();
      }
    }

    private void menuItemOk_Click(object sender, EventArgs e)
    {
      if (this.fieldsFactory != null)
        this.fieldsFactory.SaveSettings();
      this.Close();
    }

    private void menuItemCancel_Click(object sender, EventArgs e)
    {
      this.Close();
    }

    private void MainForm_Closing(object sender, CancelEventArgs e)
    {
      if (this.fieldsFactory != null && this.fieldsFactory.HasConfigChanged())
      {
        this.fieldsFactory.OnClosing();
      }
    }

    private void MainForm_Load(object sender, EventArgs e)
    {
    }

    private void MainForm_Activated(object sender, EventArgs e)
    {
    }
  }
}